//
//  NCFilterBoxSearchHeaderView.swift
//  FilterBox
//
//  Created by 张文晏 on 2018/11/12.
//  Copyright © 2018 张文晏. All rights reserved.
//

import UIKit

class NCFilterBoxSearchHeaderView: UIView {
    
    public let textField = SearchTextField()
    
    public var searchClosure: ((_ text: String?)->())?
    
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        backgroundColor = UIColor(hex:0xffffff)
        addSubview(textField)
        textField.snp.makeConstraints { make in
            make.top.equalTo(8)
            make.leading.equalTo(16)
            make.bottom.equalTo(-8)
            make.trailing.equalTo(-16)
        }
        textField.backgroundColor = UIColor(white: 0, alpha: 0.04)
        textField.delegate = self
        let line = UIView()
        addSubview(line)
        line.snp.makeConstraints { make in
            make.leading.bottom.trailing.equalToSuperview()
            make.height.equalTo(1)
        }
        line.backgroundColor = UIColor(hex: 0xeeeeee)
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
}

extension NCFilterBoxSearchHeaderView: UITextFieldDelegate {
    func textFieldShouldReturn(_ textField: UITextField) -> Bool {
        textField.resignFirstResponder()
        searchClosure?(textField.text)
        return true
    }
}
